package com.qingmi.farmer.data.repository.data;

import com.wjjun.base.data.cache.CacheProviders;
import com.wjjun.base.data.db.DBManager;
import com.wjjun.base.data.db.IDBManager;
import com.qingmi.farmer.data.model.UpdateVersion;
import com.qingmi.farmer.data.repository.api.BasicApiRepository;
import com.qingmi.farmer.data.request.GetCodeReq;
import com.wjjun.base.data.respository.BaseDataRepository;
import com.wjjun.basemvpvm.data.executor.PostExecutionThread;
import com.wjjun.basemvpvm.data.executor.ThreadExecutor;
import com.wjjun.basemvpvm.data.model.SimpleEntity;
import com.wjjun.basemvpvm.data.observer.DefaultObserver;

import java.io.File;
import java.util.List;

import javax.inject.Inject;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * 基础模块
 * Created by 67535 on 2018/5/23.
 */
public class BasicDataRepository extends BaseDataRepository<BasicApiRepository> {

    private IDBManager dbManager;

    @Inject
    public BasicDataRepository(BasicApiRepository apiRepository, ThreadExecutor threadExecutor,
                               PostExecutionThread postExecutionThread,
                               DBManager dbManager, CacheProviders cacheProviders) {

        super(apiRepository, threadExecutor, postExecutionThread, cacheProviders);
        this.dbManager = dbManager;
    }


    /**
     * 获取短信验证码
     */
    public void getCode(DefaultObserver<SimpleEntity> observer, GetCodeReq param) {
        execute(apiRepository.getCode(param), observer);
    }

    /**
     * 上传图片
     */
    public void uploadImg(DefaultObserver<List<String>> observer, File file) {
        RequestBody body = RequestBody.create(MediaType.parse("application/octet-stream"), file);
        MultipartBody.Part req = MultipartBody.Part.createFormData("imgFile", file.getName(), body);
        execute(apiRepository.uploadImg(req), observer);
    }

    /**
     * 检查版本
     */
    public void updateVersion(DefaultObserver<UpdateVersion> observer) {
        execute(apiRepository.updateVersion(), observer);
    }

}
